/*
* @Author: slp
* @Date:   2018-06-12 11:32:04
* @Last Modified by:   slp
* @Last Modified time: 2018-06-26 11:40:40
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "kifydisassembler.h"

// static void test()
// {
// 	unsigned int mov_inst[] = {
// 		0x14000000,
// 		0x94000002,
// 		0x8b0500a3,
// 		0x2560c141,
// 		0xa5e0a461,
// 		0x1,
// 		0x17fffff9,
// 	};
// 	const char *ailas;
// 	unsigned long pc = 0;
// 	for(int i=0; i<sizeof(mov_inst)/sizeof(*mov_inst); i++){
// 		ailas = disassemble_aarch64(pc, mov_inst[i]);
// 		printf("%s\n", ailas);
// 	}
// }

static void help(int argc, char *argv[])
{
	printf("usage: %s inst\n", argv[0]);
	printf("  eg: %s 0x14000000\n", argv[0]);
	printf("  output: \n");
	// printf("        %s\n", disassemble_aarch64(0, 0x14000000u));
}

int main(int argc, char *argv[]) {
	unsigned long inst;
	void *disas;
	if(argc != 2) {
		help(argc, argv);
		exit(1);
	}
	disas = new_disassemble();
	inst = strtoul(argv[1], NULL, 16);
	printf("0x%08x : ", inst);
	printf("%s\n", kify_disassemble(disas, 0, inst));
	// printf("%s\n", disassemble_aarch64(0, inst));
	release_disassemble(disas);
	return 0;
}
